package com.ljx.itbbs.server.mall.controller;

import com.ljx.itbbs.common.domain.vo.resp.ApiResult;
import com.ljx.itbbs.common.domain.vo.resp.PageResp;
import com.ljx.itbbs.common.utils.ServletUtil;
import com.ljx.itbbs.server.mall.domain.vo.req.OrderReq;
import com.ljx.itbbs.server.mall.domain.vo.req.OrderSaveReq;
import com.ljx.itbbs.server.mall.domain.vo.req.OrderSubmitReq;
import com.ljx.itbbs.server.mall.domain.vo.resp.OrderResp;
import com.ljx.itbbs.server.mall.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "订单接口")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("保存订单")
    @PostMapping("/save")
    public ApiResult<Long> saveOrder(@Valid @RequestBody OrderSaveReq req){

        return ApiResult.success(orderService.saveOrder(ServletUtil.getUserId(), req));
    }

    @ApiOperation("确认订单")
    @PostMapping("/submit")
    public ApiResult<Void> submitOrder(@Valid @RequestBody OrderSubmitReq req){
        orderService.submitOrder(ServletUtil.getUserId(), req);

        return ApiResult.success();
    }

    @ApiOperation("查询我的订单")
    @GetMapping("/list")
    public ApiResult<PageResp<OrderResp>> userOrderList(@Valid OrderReq req){

        return ApiResult.success(orderService.getUserOrderList(ServletUtil.getUserId(), req));
    }

}
